﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ClientRegister
{
    public partial class ListEmployeesForm : Form
    {

        EmployeesDataProvider emp = new EmployeesDataProvider();
        SynchronizeData Sync = new SynchronizeData();

        public ListEmployeesForm()
        {
            InitializeComponent();
        }

        private void ListEmployeesForm_Load(object sender, EventArgs e)
        {
            gridListEmp.DataSource = emp.SelectAllEmp().Tables[0];
        }

        private void btnChange_Click(object sender, EventArgs e)
        {
            if(gridListEmp.SelectedCells.Count > 0)
            {
                ChangeInfoEmpForm info = new ChangeInfoEmpForm();
                info.ID = gridListEmp.CurrentRow.Cells["ID"].Value.ToString();
                info.pass = gridListEmp.CurrentRow.Cells["Password"].Value.ToString();
                info.Name = gridListEmp.CurrentRow.Cells["FullName"].Value.ToString();
                info.gender = gridListEmp.CurrentRow.Cells["IDgender"].Value.ToString();
                info.birthday = gridListEmp.CurrentRow.Cells["Birthday"].Value.ToString();
                info.addr = gridListEmp.CurrentRow.Cells["Address"].Value.ToString();
                info.role = gridListEmp.CurrentRow.Cells["IDRole"].Value.ToString();
                info.note = gridListEmp.CurrentRow.Cells["Note"].Value.ToString();
                info.phone = gridListEmp.CurrentRow.Cells["PhoneNum"].Value.ToString();
                info.Show();
            }
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (gridListEmp.SelectedCells.Count > 0)
            {
                string ID = gridListEmp.CurrentRow.Cells["ID"].Value.ToString();

                string xml = emp.SelectAndConvertXMLEmp(ID);
                if (emp.deleteEmp(ID) != 0)
                {
                    Sync.transfDataForDeleteMethod(xml, Sync.EmployTb);
                    MessageBox.Show("Đã xóa");
                }
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnRefesh_Click(object sender, EventArgs e)
        {
            gridListEmp.DataSource = emp.SelectAllEmp().Tables[0];
        }
    }
}
